package com.bw.unit3.uitl

import android.app.Application
import android.content.Context
import android.content.SharedPreferences

/**
 *
 * @ClassName: SpUtil
 * @Description: java类作用描述
 * @Author: zhangyanchao
 * @CreateDate: 2024/9/13 10:07 AM
 * @Version: 1.0
 */
class SpUtil {
    //伴生对象
    companion object {
        private lateinit var sharedPreferences: SharedPreferences
        //初始化
        fun init(context: Context) {
            sharedPreferences = context.getSharedPreferences("shop", Application.MODE_PRIVATE)
        }

        fun putString(key: String, value: String) {
            sharedPreferences.edit().putString(key, value).commit()
        }

        fun putInt(key: String, value: Int) {
            sharedPreferences.edit().putInt(key, value).commit()
        }
        fun putLong(key: String,value:Long){
            sharedPreferences.edit().putLong(key, value).commit()
        }

        fun getString(key: String): String {
            return sharedPreferences.getString(key, "").toString()
        }

        fun getInt(key: String): Int {
            return sharedPreferences.getInt(key, 0)
        }
    }
}